//	TestParser.java

import java.io.*;

/** 
	Test class for the Parser class of the interpreter.

	@author Teresa Cole
	@version Spring 2005
*/
public class TestParser implements Token
{

/** 	Tests the Parser class of the Interpreter project.
	 @param args can be used to specify the mode.  If it exists, the
	 first element should be <tt>-c</tt> for syntax checking and
	 <tt>-p</tt> for building a parse tree.  The default is <tt>-p</tt>.
*/
	static public void main(String[] args)  throws IOException
	{
	Lexeme parseTree = new Lexeme( UNKNOWN);
	boolean printMode = true;
	
	System.out.println( "Program TestParser ");

	if (args.length>0  && args[0].equals("-c"))
	    printMode = false;

	Lexer scanner = new Lexer( System.in);
	Parser parser = new Parser( scanner);
	do
	    {
	    try
		{
		parseTree = parser.statement();
		if (printMode)
		    {
		    if (parseTree != null)
			parseTree.printTree(System.out, 0);
		    }
		else
		    System.out.println( "OK");
		}
	    catch (Exception e)
		{
		System.out.println( "INVALID");
		System.err.println( e);
		/*e.printStackTrace();*/
		}
	    }
	while ( parseTree!= null && parseTree.getType()!=EOF);

	System.out.flush();
	}
	
}
